package com.example.administrator.himalaya.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.administrator.himalaya.adapter.MyAdapter3;
import com.example.administrator.himalaya.R;
import com.example.administrator.himalaya.service.service;
import com.example.administrator.himalaya.entity.castentity.Entity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class Main2Activity extends AppCompatActivity implements Callback<Entity>, View.OnClickListener {
    private List<Entity.DataEntity.TopRadiosEntity> PHB_datas;
    private MyAdapter3 mAdapter3;
    private ListView mListView;
    private service mService;

    //    private service service;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ImageView back = (ImageView) findViewById(R.id.back);
        back.setOnClickListener(this);
        mListView = (ListView) findViewById(R.id.listView);
//        service = new Retrofit.Builder()
//                .baseUrl("http://live.ximalaya.com/")
//                .addConverterFactory(GsonConverterFactory.create())
//                .build()
//                .create(service.class);
//        service.getList().enqueue(this);
        mService = new Retrofit.Builder()
                .baseUrl("http://live.ximalaya.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(service.class);
        mService.getList().enqueue(this);
        PHB_datas = new ArrayList<>();
        mAdapter3 = new MyAdapter3(this, PHB_datas);
        mListView.setAdapter(mAdapter3);
    }

    @Override
    public void onResponse(Call<Entity> call, Response<Entity> response) {
        PHB_datas.addAll(response.body().getData().getTopRadios());
        mAdapter3.notifyDataSetChanged();
    }

    @Override
    public void onFailure(Call<Entity> call, Throwable t) {

    }

    @Override
    public void onClick(View view) {
        finish();
    }
}
